/**
 * Quad Shape
 */

include(['shapes.Mesh', 'Vector2', 'shapes.Triangle'], 

function(){
	declare('shapes.Quad');
	Quad = Mesh.extend({
		init: function(p1, p2, p3, p4){
			this._super(p1,p2,p3,p4);
		},
		north : function(){
			return new Line(this._meshdata[0], this._meshdata[3]);
		},	
		south : function(){
			return new Line(this._meshdata[2], this._meshdata[1]);
		}
	}, 'Quad');
	
	Quad.square = function(p1, length){
		p1 = new Vector2(p1.x, p1.y);
		var p2 = new Vector2(p1.x, p1.y+length);
		var p3 = new Vector2(p1.x+length, p1.y+length);
		var p4 = new Vector2(p1.x+length, p1.y);
		return new Quad(p1, p2, p3, p4);
	};
	Quad.rectangle = function(p1, width, height){
		p1 = new Vector2(p1.x, p1.y);
		var p2 = new Vector2(p1.x, p1.y+height);
		var p3 = new Vector2(p1.x+width, p1.y+height);
		var p4 = new Vector2(p1.x+width, p1.y);
		return new Quad(p1, p2, p3, p4);
	};
	Quad.fromPoints = function(p1, p2){
		var width = Math.abs(p2.x - p1.x);
		var height = Math.abs(p2.y - p1.y);
		return Quad.rectangle(p1, width, height);
	};
});